package com.cskaoyan.market.service.Impl;

import com.cskaoyan.market.db.domain.MarketFeedback;
import com.cskaoyan.market.db.domain.MarketFeedbackExample;
import com.cskaoyan.market.db.mapper.MarketFeedbackMapper;
import com.cskaoyan.market.service.MarketFeedbackService;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 付诚
 * @Date: 2024/5/6 21:27
 * @Description:
 */
@Service
public class MarketFeedbackServiceImpl implements MarketFeedbackService {

    @Autowired
    private MarketFeedbackMapper marketFeedbackMapper;
    @Override
    public List<MarketFeedback> list(Integer page, Integer limit, String username, String sort, String order,String id) {
        MarketFeedbackExample marketFeedbackExample = new MarketFeedbackExample();

        marketFeedbackExample.setOrderByClause(sort + " " + order);
        MarketFeedbackExample.Criteria criteria = marketFeedbackExample.createCriteria();
        if (!StringUtils.isEmpty(username)) {
            criteria.andUsernameLike("%" + username + "%");
        }
        if (StringUtils.isNotEmpty(id)) {
            criteria.andIdEqualTo(Integer.parseInt(id));
        }

        //两个参数：当前页；每页数量
        PageHelper.startPage(page, limit);

        List<MarketFeedback> marketFeedbackList = marketFeedbackMapper.selectByExample(marketFeedbackExample);
        return marketFeedbackList;
    }
}
